package com.itheima.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 预约套餐管理
 */


@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference //发布到ZooKeeper
    private SetmealService setmealService;

    @RequestMapping("/findAllSetmeal")
    public Result findAll() {
        try {
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, list);//一定要返回数据
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }
    }

    //根据套餐ID查询套餐详细(套餐基本信息,套餐对应的检查组信息,检查组对应的检查项信息)
    @RequestMapping("/findById")
    public Result findById(int id) {

        Setmeal setmeal = null;
        try {
            setmeal = setmealService.findById(id);
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }
}
